﻿using System;
using NDBGen.Descriptors.Columns.Tokens;

namespace NDBGen.Plugins.Descriptors.Columns.Tokens
{
    [ColumnTokenScriptSnippetGenerator(typeof(DefaultValueTokenDescriptor))]
    public sealed class SqlServerDefaultValueTokenCodeGenerator : SqlServerColumnTokenScriptSnippetGeneratorBase, IOrderedMetadata
    {        
        private const String SQL_FORMAT = "constraint [DF__{0}_{1}] default ({2})";

        protected override void WriteSql(IIndentedTextWriter writer)
        {
            writer.Write(SQL_FORMAT, this.Descriptor.Table.Name, this.Descriptor.Column.Name, this.Descriptor.TokenValue);
        }

        Int32 IOrderedMetadata.GenerationIndex { get { return 1; } }
    }
}